#include <iostream>
#include <fstream>
#include <memory>
#include "NetworkSnapshotProviderRemote.h"
#include "NetworkSnapshotTextDumper.h"
#include "NetworkSnapshotGraphVizDumper.h"
#include "ViewerException.h"

int main(int argc, char* argv[]) {
  if (argc < 2) {
    std::cerr << "Usage: [collector ip]" << std::endl;
    return -1;
  }
  
  std::ofstream out("out.fdp");
  
  try {  
    std::auto_ptr<INetworkSnapshotProvider> snapshotProvider(
      new NetworkSnapshotProviderRemote(argv[1]));
    std::auto_ptr<INetworkSnapshotDumper> snapshotDumperText(
      new NetworkSnapshotTextDumper());
    std::auto_ptr<INetworkSnapshotDumper> snapshotDumperGrapViz(
      new NetworkSnapshotGraphVizDumper());

    std::auto_ptr<NetworkSnapshot> 
      snapshot(snapshotProvider->getSnapshot(std::cerr));
    snapshotDumperGrapViz->dump(out, snapshot.get());
  } catch (ViewerException& ex) {
    std::cerr << "Sorry, Error occured: " << std::endl
              << ex.what() << std::endl;
  }
  out.close();
  return 0;
}
